package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.service.IProbeCaptureConfigService;
import com.yuandian.management.vo.OriginalDataFilterParams;
import com.yuandian.management.vo.OriginalDataFilterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 探针捕获规则配置
 *
 * @author zhoutian
 * @date 2021/1/20 9:39
 */
@RestController
@RequestMapping("/metadata/probe/capture/config")
public class ProbeCaptureConfigController {
	@Autowired
	private IProbeCaptureConfigService probeCaptureConfigService;

	/**
	 * 查询原始包捕获规则数据
	 *
	 * @param params 参数
	 * @return Result
	 */
	@ResponseBody
	@RequestMapping("/list")
	public R getOriginalDataFilter(OriginalDataFilterParams params) {
		Page<OriginalDataFilterVo> list = probeCaptureConfigService.queryOriginalDataFilterResultMap(params);
		return R.ok(list);
	}

	/**
	 * 根据ID查询原始包捕获规则数据
	 *
	 * @param id 数据行id
	 * @return Result
	 */
	@GetMapping(value = "/getOriginalDataFilter/{id}")
	public R getOriginalDataFilterById(@PathVariable Integer id) {
		return R.ok(probeCaptureConfigService.findById(id));
	}


	/**
	 * 清理数据
	 *
	 * @param clearType 参数
	 * @return Result
	 */
	@DeleteMapping("/clearData/{clearType}")
	public R clearData(@PathVariable Integer clearType) {
		return probeCaptureConfigService.clearData(clearType);
	}


	/**
	 * 保存原始包捕获规则
	 *
	 * @param params 参数
	 * @return Result
	 */
	@PostMapping("/save")
	public R saveOriginalDataFilter(@RequestBody OriginalDataFilterVo params) {
		return probeCaptureConfigService.save(params);
	}


	/**
	 * 修改原始包捕获规则  禁用启用
	 *
	 * @param params 参数
	 * @return Result
	 */
	@PostMapping("/updateStatus")
	public R updateStatus(@RequestBody OriginalDataFilterParams params) {
		return probeCaptureConfigService.updateStatusByIds(params.getIds(), params.getIsEnable());
	}


	/**
	 * 删除探针数据过滤信息
	 *
	 * @param ids id集
	 * @return Result
	 */
	@DeleteMapping("/{ids}")
	public R deleteOriginalDataFilterByIds(@PathVariable List<Integer> ids) {
		return probeCaptureConfigService.deleteByIds(ids);
	}

	/**
	 * 保存原始包捕获规则
	 *
	 * @param params 参数
	 * @return Result
	 */
	@PostMapping("/sendFilterRule")
	public R sendFilterRule(@RequestBody OriginalDataFilterParams params) {
		return probeCaptureConfigService.syncFilterRule(params.getIds());
	}

	/**
	 * 查询原始包捕获规则数据
	 *
	 * @return Result
	 */
	@ResponseBody
	@RequestMapping("/findName")
	public R findName() {
		return R.ok( probeCaptureConfigService.findName());
	}

}
